<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>本地缓存设计指南</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .content-card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            transition: all 0.3s ease;
        }
        
        .content-card:hover {
            transform: translateY(-2px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
        }
        
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 24px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        .highlight-box {
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
            color: white;
            padding: 2px 8px;
            border-radius: 4px;
            display: inline-block;
            font-weight: 500;
        }
        
        .feature-icon {
            width: 60px;
            height: 60px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 16px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 24px;
            margin-bottom: 16px;
        }
        
        .mermaid {
            background: transparent;
            padding: 20px;
        }
        
        .drop-cap {
            float: left;
            font-size: 4em;
            line-height: 0.8;
            margin: 0.1em 0.1em 0 0;
            font-weight: 700;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            font-family: 'Noto Serif SC', serif;
        }
        
        .strategy-card {
            background: white;
            border-radius: 16px;
            padding: 24px;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
            transition: all 0.3s ease;
            border: 1px solid #e5e7eb;
        }
        
        .strategy-card:hover {
            transform: translateY(-4px);
            box-shadow: 0 12px 32px rgba(0, 0, 0, 0.12);
        }
        
        .metric-badge {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 8px 16px;
            border-radius: 24px;
            font-size: 14px;
            font-weight: 500;
            display: inline-block;
            margin: 4px;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-24">
        <div class="container mx-auto px-6">
            <div class="max-w-4xl mx-auto text-center">
                <h1 class="text-5xl md:text-6xl font-bold mb-6 leading-tight">
                    本地缓存设计指南
                </h1>
                <p class="text-xl md:text-2xl opacity-90 mb-8">
                    深入探索高性能缓存系统的设计原理与最佳实践
                </p>
                <div class="flex justify-center space-x-4 text-sm">
                    <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full">
                        <i class="fas fa-clock mr-2"></i>阅读时间：15分钟
                    </span>
                    <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full">
                        <i class="fas fa-layer-group mr-2"></i>架构设计
                    </span>
                </div>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="container mx-auto px-6 py-12">
        <!-- Introduction -->
        <div class="content-card rounded-2xl shadow-xl p-8 mb-12">
            <p class="text-lg leading-relaxed text-gray-700">
                <span class="drop-cap">随</span>着系统的复杂性和数据量的增加，如何快速响应用户请求、减少服务器的压力、提高系统的吞吐量，成为了架构设计中的重要挑战。在这种背景下，<span class="highlight-box">本地缓存</span>作为一种提高性能的技术手段，受到了广泛的关注和应用。
            </p>
            <p class="text-lg leading-relaxed text-gray-700 mt-4">
                本地缓存是一种将数据存储在应用程序本地内存中的机制，它能够减少对外部数据源的访问，从而大幅度降低延迟，提升应用程序的响应速度。相比分布式缓存，本地缓存的优势在于它的速度更快、实现更简单，不需要考虑网络传输的延迟和分布式一致性的问题。
            </p>
        </div>

        <!-- Core Concepts Visualization -->
        <div class="content-card rounded-2xl shadow-xl p-8 mb-12">
            <h2 class="section-title text-3xl font-bold mb-8 text-gray-800">缓存架构概览</h2>
            <div class="mermaid">
                graph TB
                    A[用户请求] --> B{本地缓存}
                    B -->|命中| C[返回缓存数据]
                    B -->|未命中| D[查询数据源]
                    D --> E[数据库/远程服务]
                    E --> F[更新缓存]
                    F --> G[返回数据]
                    
                    style A fill:#f093fb,stroke:#f093fb,color:#fff
                    style B fill:#667eea,stroke:#667eea,color:#fff
                    style C fill:#4ade80,stroke:#4ade80,color:#fff
                    style E fill:#764ba2,stroke:#764ba2,color:#fff
            </div>
        </div>

        <!-- Basic Concepts -->
        <div class="content-card rounded-2xl shadow-xl p-8 mb-12">
            <h2 class="section-title text-3xl font-bold mb-8 text-gray-800">本地缓存的基本概念</h2>
            
            <div class="grid md:grid-cols-2 gap-8 mb-8">
                <div>
                    <div class="feature-icon">
                        <i class="fas fa-rocket"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3">核心思想</h3>
                    <p class="text-gray-600 leading-relaxed">
                        本地缓存的核心思想是<strong>空间换时间</strong>。通过预先将数据加载到本地内存中，避免每次访问都去请求外部数据源，显著减少访问延迟。
                    </p>
                </div>
                
                <div>
                    <div class="feature-icon">
                        <i class="fas fa-cogs"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3">实现方式</h3>
                    <p class="text-gray-600 leading-relaxed">
                        从简单的HashMap到专业的缓存框架如Caffeine、Ehcache，不同的实现方式适用于不同的场景需求。
                    </p>
                </div>
            </div>

            <div class="bg-gray-50 rounded-xl p-6">
                <h4 class="font-semibold text-lg mb-4 text-gray-800">
                    <i class="fas fa-check-circle text-green-500 mr-2"></i>本地缓存的优势
                </h4>
                <div class="grid md:grid-cols-3 gap-4">
                    <div class="bg-white rounded-lg p-4">
                        <h5 class="font-semibold text-purple-600 mb-2">高性能</h5>
                        <p class="text-sm text-gray-600">访问速度极快，通常只需几个纳秒</p>
                    </div>
                    <div class="bg-white rounded-lg p-4">
                        <h5 class="font-semibold text-purple-600 mb-2">简化架构</h5>
                        <p class="text-sm text-gray-600">实现简单，降低系统复杂性</p>
                    </div>
                    <div class="bg-white rounded-lg p-4">
                        <h5 class="font-semibold text-purple-600 mb-2">减少依赖</h5>
                        <p class="text-sm text-gray-600">减轻外部数据源负载</p>
                    </div>
                </div>
            </div>
        </div>

        <!-- Key Design Elements -->
        <div class="content-card rounded-2xl shadow-xl p-8 mb-12">
            <h2 class="section-title text-3xl font-bold mb-8 text-gray-800">缓存设计的关键要素</h2>
            
            <div class="space-y-6">
                <div class="strategy-card">
                    <h3 class="text-xl font-semibold mb-4 text-purple-700">
                        <i class="fas fa-database mr-2"></i>数据结构选择
                    </h3>
                    <p class="text-gray-600 mb-4">
                        数据结构的选择对于缓存的性能至关重要。HashMap提供O(1)的查询复杂度，LinkedHashMap支持LRU策略，而专业缓存库如Caffeine则提供了更丰富的功能和优化。
                    </p>
                    <div class="flex flex-wrap">
                        <span class="metric-badge">HashMap</span>
                        <span class="metric-badge">ConcurrentHashMap</span>
                        <span class="metric-badge">LinkedHashMap</span>
                        <span class="metric-badge">Caffeine</span>
                    </div>
                </div>

                <div class="strategy-card">
                    <h3 class="text-xl font-semibold mb-4 text-purple-700">
                        <i class="fas fa-memory mr-2"></i>存储策略
                    </h3>
                    <p class="text-gray-600 mb-4">
                        根据应用需求选择合适的存储位置：堆内存访问速度快但受JVM限制，堆外内存可避免GC影响，磁盘存储适合大规模持久化数据。
                    </p>
                </div>

                <div class="strategy-card">
                    <h3 class="text-xl font-semibold mb-4 text-purple-700">
                        <i class="fas fa-clock mr-2"></i>过期策略
                    </h3>
                    <p class="text-gray-600">
                        TTL（Time to Live）设定固定生存时间，TTI（Time to Idle）根据访问频率决定过期时间，合理的过期策略能有效防止缓存数据过时。
                    </p>
                </div>
            </div>
        </div>

        <!-- Eviction Strategies -->
        <div class="content-card rounded-2xl shadow-xl p-8 mb-12">
            <h2 class="section-title text-3xl font-bold mb-8 text-gray-800">缓存淘汰策略</h2>
            
            <div class="mb-8">
                <div class="mermaid">
                    graph LR
                        A[缓存淘汰策略] --> B[LRU]
                        A --> C[LFU]
                        A --> D[FIFO]
                        A --> E[ARC]
                        A --> F[Random]
                        
                        B --> B1[最近最少使用]
                        C --> C1[最少使用频率]
                        D --> D1[先进先出]
                        E --> E1[自适应替换]
                        F --> F1[随机淘汰]
                        
                        style A fill:#667eea,stroke:#667eea,color:#fff
                        style B fill:#f093fb,stroke:#f093fb,color:#fff
                        style C fill:#f093fb,stroke:#f093fb,color:#fff
                        style D fill:#f093fb,stroke:#f093fb,color:#fff
                        style E fill:#f093fb,stroke:#f093fb,color:#fff
                        style F fill:#f093fb,stroke:#f093fb,color:#fff
                </div>
            </div>

            <div class="grid md:grid-cols-2 gap-6">
                <div class="bg-gradient-to-br from-purple-50 to-pink-50 rounded-xl p-6">
                    <h3 class="text-xl font-semibold mb-